package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 用量单位
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum DoseUnit {
    PILL("PILL", 1, "片"),
    LITRE("LITRE", 3, "L/升"),
    GRAM("GRAM", 5, "g/克"),
    MILLILITER("MILLILITER", 2, "ml/毫升"),
    BOTTLE("BOTTLE", 4, "瓶"),
    KILOGRAM("KILOGRAM", 6, "kg/千克"),
    MILLIGRAM("MILLIGRAM", 7, "mg/毫克"),
    BAG("BAG", 8, "袋"),
    DROP("DROP", 9, "滴"),
    UNIT("UNIT", 10, "单位"),
    MICROGRAM("MICROGRAM", 11, "μg/微克"),
    SPRINKLE("SPRINKLE", 12, "喷"),
    PARTICLE("PARTICLE", 13, "粒"),
    BOLUS("BOLUS", 14, "丸"),
    GAG("GAG", 15, "枚"),
    GRAIN("GRAIN", 16, "颗"),
    BRANCH("BRANCH", 17, "支"),
    OTHER("OTHER", 0, "其他");

    // 类型
    private final String code;
    // 描述
    private final String desc;
    // 编号
    private final Integer num;

    DoseUnit(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    /**
     * 把所有枚举定义转换成实体
     *
     * @return List<DoseUnit>
     */
    public static List<DoseUnit> getList() {
        List<DoseUnit> list = Lists.newArrayList();

        DoseUnit[] ts = DoseUnit.values();
        for (DoseUnit type : ts) {
            list.add(type);
        }
        return list;
    }

    public static DoseUnit getDoseUnit(String code) {
        DoseUnit[] ts = DoseUnit.values();
        for (DoseUnit t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static DoseUnit getDoseUnitByDesc(String desc) {
        DoseUnit[] ts = DoseUnit.values();
        for (DoseUnit t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
